package fr.efrei.tradesys.struts.actions.currencies;

import java.util.Comparator;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import fr.efrei.tradesys.hibernate.beans.AppUser;
import fr.efrei.tradesys.hibernate.beans.Owned;
import fr.efrei.tradesys.hibernate.factory.DaoFactory;

public class DisplayPortfolioAction extends ActionSupport
{

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	private static Log				LOGGER						= LogFactory
																									.getLog(DisplayPortfolioAction.class);
	private List<Owned>				owned;
	private Comparator<Owned>	ownedCurrencyComp;

	@SuppressWarnings("unchecked")
	public String execute() throws Exception
	{
		LOGGER.info("Execution of " + this.getClass().getName());
		Map<String, Object> session = ActionContext.getContext().getSession();
		owned = DaoFactory.getInstance().getOwnedDao()
				.getOwned((AppUser) session.get("user"));
		ownedCurrencyComp = new BeanComparator("currency.code");
		return SUCCESS;
	}

	public List<Owned> getOwned()
	{
		return owned;
	}

	public void setOwned(List<Owned> owned)
	{
		this.owned = owned;
	}

	public Comparator<Owned> getOwnedCurrencyComp()
	{
		return ownedCurrencyComp;
	}

	public void setOwnedCurrencyComp(Comparator<Owned> ownedCurrencyComp)
	{
		this.ownedCurrencyComp = ownedCurrencyComp;
	}

}
